home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / examples / programs / rule_create.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-08  |  6.6 KB  |  172 lines

  1. #ifndef    lint
  2. static char SccsId[]= "@(#)rule_create.c    V1.13    3/13/95";
  3. #endif
  4.  
  5. #include <windows.h>
  6. /*                                                                     */
  7. /*                                                                     */
  8. /*   file name - rule_create.c                                         */
  9. /*                                                                     */
  10. /*   This example program demostrates how to programatically create    */
  11. /*   and modify rules for a view and its objects.                      */
  12. /*                                                                     */
  13.  
  14. #include "std.h"
  15. #include "dvstd.h"
  16. #include "dvtools.h"
  17. #include "Tfundecl.h"
  18. #include "VOfundecl.h"
  19. #include "dvrule.h"
  20.  
  21. /* Functions defined in rule_create.c */
  22.  
  23. /*
  24.  *    MAIN PROGRAM
  25.  */
  26. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  27.                      LPSTR lpCmdLine,  int nCmdShow  )
  28.   {
  29.   VIEW view;
  30.   RULE_CONDITION cond;
  31.   RULE_ACTION action;
  32.   OBJECT drawing, rule, menu_obj, quit_obj;
  33.   ADDRESS *vdplist;
  34.   int numvdps, event_type, cond_type, action_type;
  35.   VARDESC vdp;
  36.   DSVAR dsv;
  37.  
  38.   int argc;
  39.   char **argv;
  40.   char mes_str[100];
  41.  
  42.   make_argv(&argc,&argv,GetCommandLine());
  43.    TInit ((char *) NULL, (char *) NULL);  /* use DVPATH config var */
  44.  
  45.   view = TviLoad ("base_wo_ru.v");
  46.   drawing = TviGetDrawing (view);
  47.  
  48.   /*                                                                 */
  49.   /* Add the rule :                                                  */
  50.   /*     On: V_RE_DRAW  If: V_RC_ALWAYS  Do: V_RA_STOP_DYNAMICS      */
  51.   /* to the view                                                     */
  52.   /*                                                                 */
  53.  
  54.   /* Create a default rule */
  55.   rule = VOruCreate ();
  56.  
  57.   /* Set the appropriate info to the rule. Note: V_RC_ALWAYS
  58.    | and V_RA_STOP_DYNAMICS both don't need any args
  59.    */
  60.   VOruSetInfo (rule, V_R_EVENT, (int) V_RE_DRAW, V_R_CONDITION,
  61.           (int) V_RC_ALWAYS, (RULE_ARG) 0, (RULE_ARG) 0, (RULE_ARG) 0,
  62.                V_R_ACTION, (int) V_RA_STOP_DYNAMICS,
  63.                (RULE_ARG) 0, (RULE_ARG) 0, V_END_OF_LIST);
  64.  
  65.   /* Append the rule to the view's rule deque */
  66.   VOruAddToOb (drawing, rule, -1);
  67.  
  68.   /*                                                                   */
  69.   /* Add the following rules to the menu input object named 'menu.obj' */
  70.   /*   On: V_RE_DONE  If: Obj's Var = <1.0>                            */
  71.   /*       Do: Go to View <sub1.v>                                     */
  72.   /*   On: V_RE_DONE  If: Obj's Var = <2.0>                            */
  73.   /*       Do: Overlay <dyn_toggle.obj> from <sub2.v>                  */
  74.   /*                                                                   */
  75.  
  76.   /* Get the menu input object named 'menu.obj' */
  77.   menu_obj = TdrGetNamedObject (drawing, "menu.obj");
  78.  
  79.   /* Get the menu input object's vdp and dsv */
  80.   VOinGetVarList (menu_obj, &vdplist, &numvdps);
  81.   vdp = (VARDESC) vdplist[0];
  82.   dsv = (DSVAR) TvdGetDataSourceVariable (vdp);
  83.  
  84.   /* Create a default rule */
  85.   rule = VOruCreate ();
  86.   VOruSetInfo (rule, V_R_EVENT, (int) V_RE_DONE, V_R_CONDITION,
  87.                (int) V_RC_DSV_VALUE, (RULE_ARG) dsv,
  88.                (RULE_ARG) V_RC_EQUAL, (RULE_ARG) "1.0",
  89.                V_R_ACTION, (int) V_RA_NEXT, (RULE_ARG) "sub1.v",
  90.                (RULE_ARG) 0, V_END_OF_LIST);
  91.  
  92.   /* Append to the menu_obj's rule deque */
  93.   VOruAddToOb (menu_obj, rule, -1);
  94.  
  95.   /* Create a default rule */
  96.   rule = VOruCreate ();
  97.   VOruSetInfo (rule, V_R_EVENT, (int) V_RE_DONE, V_R_CONDITION,
  98.                (int) V_RC_DSV_VALUE, (RULE_ARG) dsv,
  99.                (RULE_ARG) V_RC_EQUAL, (RULE_ARG) "2.0",
  100.                V_R_ACTION, (int) V_RA_OVERLAY_OBJ,
  101.                (RULE_ARG) "dyn_toggle.obj", (RULE_ARG) "sub2.v",
  102.                V_END_OF_LIST);
  103.  
  104.   /* Append to the menu_obj's rule deque */
  105.   VOruAddToOb (menu_obj, rule, -1);
  106.  
  107.  
  108.   /*                                                                   */
  109.   /* Add rule to the object named 'quit.obj' to quit prototype         */
  110.   /*                                                                   */
  111.  
  112.   /* Get the object named 'quit.obj' */
  113.   quit_obj = TdrGetNamedObject (drawing, "quit.obj");
  114.  
  115.   /* Create a default rule */
  116.   rule = VOruCreate ();
  117.   VOruSetInfo (rule, V_R_EVENT, (int) V_RE_PICK, V_R_CONDITION,
  118.           (int) V_RC_ALWAYS, (RULE_ARG) 0, (RULE_ARG) 0, (RULE_ARG) 0,
  119.                V_R_ACTION, (int) V_RA_QUIT, (RULE_ARG) 0, (RULE_ARG) 0,
  120.                V_END_OF_LIST);
  121.  
  122.   /* Append to the quit_obj's rule deque */
  123.   VOruAddToOb (quit_obj, rule, -1);
  124.  
  125.   /*                                                                   */
  126.   /* Now for example, if we want to change menu_obj's second rule      */
  127.   /* from -->         On: V_RE_DONE  If: Obj's Var = <2.0>             */
  128.   /*                      Do: Overlay <dyn_toggle.obj> from <sub2.v>   */
  129.   /* to   -->         On: V_RE_DONE  If: Obj's Var => <2.0>            */
  130.   /*                      Do: Overlay <dyn_menu.obj> from <sub2.v>     */
  131.   /*                                                                   */
  132.  
  133.   /* First, get the second rule of menu_obj */
  134.   rule = VOruGetFromOb (menu_obj, (int)2);
  135.  
  136.   /* Get the rule's V_R_CONDITION and V_R_ACTION info */
  137.   VOruGetInfo (rule, V_R_EVENT, &event_type, V_R_CONDITION,
  138.                &cond_type, &cond.arg[0], &cond.arg[1], &cond.arg[2],
  139.                V_R_ACTION, &action_type, &action.arg[0],
  140.                &action.arg[1], V_END_OF_LIST);
  141.  
  142.   /* Change the second arg of condition */
  143.   cond.arg[1] = (RULE_ARG) V_RC_GREATER_EQUAL_THAN;
  144.  
  145.   /* Allocate space for the new object name */
  146.   action.arg[0] = (RULE_ARG) S_ALLOC ((strlen ("dyn_menu.obj") + 1)
  147.                                       * sizeof (char));
  148.   /* Copy the new object name into the first arg of action */
  149.   strcpy ((char *) action.arg[0], "dyn_menu.obj");
  150.  
  151.   /* Set the rule info again with the new condition and action info */
  152.   VOruSetInfo (rule, V_R_EVENT, event_type, V_R_CONDITION,
  153.                cond_type, cond.arg[0], cond.arg[1], cond.arg[2],
  154.                V_R_ACTION, action_type, action.arg[0],
  155.                action.arg[1], V_END_OF_LIST);
  156.  
  157.   sprintf (mes_str,"Added and modified rules...\n");
  158.   strcat (mes_str,"Saving \"base_w_ru.v\" ...\n");
  159.   strcat (mes_str,"Use DV-Draw or DV-Play to display.\n");
  160.    MessageBox (
  161.                 GetFocus (),
  162.                 mes_str,
  163.                 "rule_create:",
  164.                 MB_OK
  165.               );
  166.   TviASCIISave (view, "base_w_ru.v");
  167.  
  168.   TviDestroy (view);
  169.   TTerminate ();
  170.   return EXIT_OK;
  171. }
  172.